// ----------------------------------
// RSDK Project: Sonic 1/Sonic 2
// Script Description: Ring Object
// Script Author: Christian Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

//-------Aliases-------//
private alias 14 : TYPE_RING

// Function declarations
reserve function Ring_DebugDraw
reserve function Ring_DebugSpawn

// Static Values

// Tables

function Ring_DebugDraw
	DrawSprite(0)
end function


function Ring_DebugSpawn
	temp5 = 14
	temp4 = 0
	CallFunction(DebugMode_SpawnObject)
	object[arrayPos0].drawOrder = 4
end function


event ObjectMain
	foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
		BoxCollisionTest(C_TOUCH, object.entityPos, -8, -8, 8, 8, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
		if checkResult == 1
			object.type = TypeName[Ring Sparkle]
			if stage.debugMode == 0
				saveRAM[997]++
				if saveRAM[997] > saveRAM[998]
					saveRAM[998] = saveRAM[997]
				end if
			end if
			object[currentPlayer].value0++
			if object[currentPlayer].value0 > 999
				object[currentPlayer].value0 = 999
			end if
			if object[currentPlayer].value0 >= ringExtraLife
				if options.gameMode < 2
					if saved.lives == 0
						player.lives++
						PlaySfx(SfxName[Life], 0)
						PauseMusic()
						ResetObjectEntity(25, TypeName[Music Event], 2, 0, 0)
						object[25].priority = PRIORITY_ACTIVE
					end if
				end if
				ringExtraLife += 100
				if ringExtraLife >= 300
					ringExtraLife = 1000
				end if
			end if
			if PlayerObject_value4 == 0
				if ringPan == 0
					PlaySfx(SfxName[Ring L], 0)
					SetSfxAttributes(SfxName[Ring L], -1, -100)
					ringPan = 1
				else
					PlaySfx(SfxName[Ring R], 0)
					SetSfxAttributes(SfxName[Ring R], -1, 100)
					ringPan = 0
				end if
			end if
			if object[currentPlayer].value0 == 50
				if options.gameMode < 2
					if saved.lives == 0
						player.continues++
						PlaySfx(SfxName[Continue], 0)
						if options.gameMode == 1
							arrayPos1 = options.saveSlot
							arrayPos1 <<= 3
							arrayPos1 += 1000
							arrayPos1 += 7		
							saveRAM[arrayPos1] = player.continues
						end if
					end if
				end if
			end if
		end if
	next
end event


event ObjectDraw
	CallFunction(SpecialSetup_Function9)
	DrawSpriteXY(ringFrame, temp0, temp1)
end event


event ObjectStartup
	LoadSpriteSheet("Special/Objects.gif")
	arrayPos0 = 32
	while arrayPos0 < 0x420
		if object[arrayPos0].type == TypeName[Ring]
			object[arrayPos0].drawOrder = 4
		end if
		arrayPos0++
	loop
	SpriteFrame(-8, -8, 16, 16, 172, 376)
	SpriteFrame(-8, -8, 16, 16, 189, 376)
	SpriteFrame(-8, -8, 16, 16, 206, 376)
	SpriteFrame(-8, -8, 16, 16, 223, 376)
	SpriteFrame(-8, -8, 16, 16, 240, 376)
	SpriteFrame(-8, -8, 16, 16, 257, 376)
	SpriteFrame(-8, -8, 16, 16, 274, 376)
	SpriteFrame(-8, -8, 16, 16, 291, 376)
	SetTableValue(TypeName[Ring], DebugMode_ObjCount, DebugMode_TypeTable)
	SetTableValue(Ring_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
	SetTableValue(Ring_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
	DebugMode_ObjCount++
end event

event RSDKDraw
	DrawSprite(0)
end event

event RSDKLoad
	LoadSpriteSheet("Special/Objects.gif")
	SpriteFrame(-8, -8, 16, 16, 172, 376)
end event
